package com.hyz.controller;

import com.hyz.model.dto.AmUpdateAssetMaintenanceRequest;
import com.hyz.model.dto.ApprovalResultRequest;
import com.hyz.model.dto.InsAssetImportRequest;
import com.hyz.model.dto.InsertAssetOutboundRequest;
import com.hyz.model.vo.*;
import com.hyz.service.permission.AssetManagerService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import pojo.ResponseResult;
import pojo.asset.repository.Repository;

import java.util.List;
import java.util.Map;

/**
 * @author HGD
 * @date 2022/10/7 23:56
 */
@Api("资产管理员")
@RestController
@RequestMapping("/assetManager")
@PreAuthorize("hasAnyAuthority('rights','assetManager')")
public class AssetManagerController {
    @Autowired
    private AssetManagerService service;

    //--------------------------------------------------
    //未入库资产批量导入

    @PostMapping("/getExcelData")
    public ResponseResult<Object> getExcelAsset(@RequestBody String importData) {
        return service.getImportResult(importData);
    }

    // ----------------------------------------------------------------
    // 资产入库

    @ApiOperation("资产管理员获取未入库资产集合")
    @PostMapping("/getUnassignedAsset")
    public ResponseResult<List<AssetResponse>> getUnassignedAsset() {
        return service.getUnassignedAsset();
    }

    @ApiOperation("资产管理员查询对应资产可入库的仓库列表")
    @PostMapping("/getEnableImportRepositories")
    public ResponseResult<List<Repository>> getEnableImportRepositories(@RequestBody Long assetId) {
        // 1. 判断传入数据是否非空
        if (assetId == null) {
            return new ResponseResult<>(400, "参数为空");
        }
        return service.getEnableImportRepositories(assetId);
    }

    @ApiOperation("资产管理员创建资产入库申请")
    @PostMapping("/insertAssetImport")
    public ResponseResult<List<AssetResponse>> insertAssetImport(@RequestBody InsAssetImportRequest request) {
        if (request.getAssetId() == null || request.getRepositoryId() == null) {
            return new ResponseResult<>(400, "参数为空");
        }
        return service.insertAssetImport(request);
    }

    @ApiOperation("资产管理员获取资产入库申请")
    @PostMapping("/amGetAssetImport")
    public ResponseResult<List<AssetImportResponse>> amGetAssetImport() {
        return service.amGetAssetImport();
    }

    //----------------------------------------------------------------
    // 资产借调

    @ApiOperation("资产管理员获取资产借调申请")
    @PostMapping("/amGetAssetSecondments")
    public ResponseResult<List<AssetSecondmentResponse>> amGetAssetSecondments() {
        return service.amGetAssetSecondments();
    }

    @ApiOperation("资产管理员获取可分配资产")
    @PostMapping("/getUnLockAssets")
    public ResponseResult<List<AssetResponse>> getUnLockAssets(@RequestBody Long assetSecondmentId) {
        return service.getUnLockAssets(assetSecondmentId);
    }

    @ApiOperation("资产管理员为借调申请分配资产并创建资产出库")
    @PostMapping("/insertAssetOutbound")
    public ResponseResult<List<AssetSecondmentResponse>> insertAssetOutbound(@RequestBody InsertAssetOutboundRequest request) {
        return service.insertAssetOutbound(request);
    }

    @ApiOperation("资产管理员获取资产出库申请")
    @PostMapping("/amGetAssetOutbounds")
    public ResponseResult<List<AssetOutboundResponse>> amGetAssetOutbounds() {
        return service.amGetAssetOutbounds();
    }

    @ApiOperation("资产管理员更新出库申请")
    @PostMapping("/amUpdateAssetOutbound")
    public ResponseResult<List<AssetOutboundResponse>> amUpdateAssetOutbound(@RequestBody ApprovalResultRequest request) {
        return service.amUpdateAssetOutbound(request);
    }

    @ApiOperation("资产管理员更新资产借调申请")
    @PostMapping("/amUpdateAssetSecondment")
    public ResponseResult<List<AssetSecondmentResponse>> amUpdateAssetSecondment(@RequestBody ApprovalResultRequest request) {
        return service.amUpdateAssetSecondment(request);
    }

    //----------------------------------------------------------------
    // 资产维修

    @ApiOperation("资产管理员获取资产维修列表")
    @PostMapping("/amGetAssetMaintenance")
    public ResponseResult<List<AssetMaintenanceResponse>> amGetAssetMaintenance() {
        return service.amGetAssetMaintenance();
    }

    @ApiOperation("资产管理员审批维修申请")
    @PostMapping("/amUpdateAssetMaintenance")
    public ResponseResult<List<AssetMaintenanceResponse>> amUpdateAssetMaintenance(@RequestBody AmUpdateAssetMaintenanceRequest request) {
        return service.amUpdateAssetMaintenance(request);
    }

    @ApiOperation("资产管理员根据资产id获取资产信息")
    @PostMapping("/getAssetById")
    public ResponseResult<Map<String, AssetResponse>> getAssetById(@RequestBody Long assetId) {
        return service.getAssetById(assetId);
    }

    //----------------------------------------------------------------------------------------------------------
    // 资产报废

    @ApiOperation("资产管理员获取资产报废申请")
    @PostMapping("/amGetAssetRetirement")
    public ResponseResult<List<AssetRetirementResponse>> amGetAssetRetirement() {
        return service.amGetAssetRetirement();
    }

    @ApiOperation("资产管理员审批报废申请")
    @PostMapping("/amUpdateAssetRetirement")
    public ResponseResult<List<AssetRetirementResponse>> amUpdateAssetRetirement(@RequestBody ApprovalResultRequest request) {
        return service.amUpdateAssetRetirement(request);
    }

    //----------------------------------------------------------------------------------------------------------
    // 资产盘点

    @ApiOperation("资产管理员获取待盘点资产集合")
    @PostMapping("/getInventoryAsset")
    public ResponseResult<List<AssetResponse>> getInventoryAsset() {
        return service.getInventoryAsset();
    }
}
